// DB Abstractions
import './load-models';
import mongoose from 'mongoose';
import { DB, DB_NAME } from '../env';
import { logger } from '../logger';
import PermissionGroupModel from './models/permGroup';
export const goose = mongoose.connect(DB, {
  dbName: DB_NAME,
});
export default goose;
(async () => {
  logger.info('Connecting to DB...');
  await goose;
  let devGroup = await PermissionGroupModel.findOne({
    groupName: 'Developers',
  });
  if (!devGroup) {
    logger.debug('Creating Developers Group...');
    devGroup = new PermissionGroupModel({
      groupName: 'Developers',
    });
    devGroup.permissions = {
      developer: true,
      managePermissions: true,
    };
    await devGroup.save();
  }
  logger.info('DB Connection Established!');
})();
